// Chromanova!!!

/*
 * Benjamin Hitov
 * Ricky Mondello
 * Brooke Evans
 * Daniel Millstein
 *
 * Ball.java - Static ball class. These balls are part of the environment and
 *      cannot be moved by the player.
 */


package chromafinal;

import java.awt.Color;
import java.awt.Graphics;

public class Ball extends LevelBall
    {
        public int mass;
	public Color color;
        public int force;
        int blahblah;
        
        final int FMOD = 4;

	protected final Color red = new Color(255, 10, 10);	
	protected final Color green = new Color(10, 230, 10);        

        public Ball (int x0, int y0, int force0)
        {
            super(x0,y0,Math.abs(force0)/3);
            force = force0;
            if (force0 > 0)
                color = red;
            else
                color = green;
	    mass = force0*Math.abs(force0) * FMOD;
	    size = Math.abs(force0)/3;
            otype = BALL;
            leftx = x - size/2;
            rightx = x + size/2;
        }

	// Constructor with player.
	public Ball(DynamicBall p, int i, int fmod){
            super( (int)p.xl+i, (int)p.yl);
	    mass = p.mass * fmod;
	}

	public void draw(Graphics g)
	{
	    g.setColor( color );
	    g.fillOval((int) (x-size/2 - Game.screenloc), (int) (y-size/2), size, size);
	}

	public void pushPlayer(Player p)
        {
            int pmass = p.mass, mod = p.cnum;
            int [] pxy = p.getRelCoords();
            double dist = distance(p);

            if (dist < (Player.SIZE_OF_MY_BALLS/2 + size/2))
            {
                p.die();
                return;
            }
            
            double dFactor = pmass * mass / Math.max(Math.pow(dist,3),150000) * mod * 0.7;

            double forces[] = new double[] {(pxy[0] - x) * dFactor,
                    (pxy[1] - y) * dFactor};

            p.xa += forces[0];
            p.ya += forces[1];
        }

        public void pushBall(DynamicBall p, int i)
        {
            double px = p.xl, py = p.yl;
            int pmass = p.mass, mod = p.cnum;


            double dist = Math.pow(Math.pow((px - (x - i)),2)
                    + Math.pow((py - y),2),0.5);

            double dFactor = Math.abs(pmass) * (mass) / Math.max(Math.pow(dist,3),150000) * mod;

            double forces[] = new double[] {(px - (x - i)) * dFactor,
                    (py - y) * dFactor};

            p.xa += forces[0];
            p.ya += forces[1];
        }

}


